package com.coocaa.ops.api.v1.home.biz;

import com.coocaa.ops.api.common.validator.PolicyValidator;
import com.coocaa.ops.api.v1.home.mapper.IModuleMapper;
import com.coocaa.ops.common.core.biz.dmp.entity.DmpRegistryRlsInfoEntity;
import com.coocaa.ops.common.core.biz.homepage.entity.HomeModuleContentConfigInfo;
import com.coocaa.ops.common.core.biz.module.entity.ModuleApkPluginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tangminghong
 * @date 2020-07-08
 */
@Service
public class ModuleBizImpl implements IModuleBiz {

    @Autowired
    private IModuleMapper moduleMapper;


    @Override
    public HomeModuleContentConfigInfo getModuleByIdAndVersion(Integer id, Integer version) {
        return moduleMapper.selectModuleByIdAndVersion(id, version);
    }

    @Override
    public List<DmpRegistryRlsInfoEntity> getModuleTabDmpInfo(Integer moduleId, Integer policyCategory, Integer moduleVersion) {
        if (PolicyValidator.isTestPolicy(policyCategory)) {
            return moduleMapper.selectModuleTabDmpInfo(moduleId, moduleVersion);
        } else {
            return moduleMapper.selectModuleTabDmpInfo(moduleId, null);
        }
    }

    @Override
    public List<ModuleApkPluginInfo> getModuleApkPluginInfo(String moduleType) {
        return moduleMapper.selectModuleApkPluginInfo(moduleType);
    }
}
